<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class home_controller extends public_controller
{
    public function __construct()
    {
        parent::__construct();
        $this->addCss('styles');
        $this->addJs('jquery.fullscreen-min');
//        $this->addJs('jquery.min');
    }

    public function index()
    {
        $style = show_style_model::get_element_by_code(show_style_model::$CODE)->style;
        if($style == show_style_model::$STYLE_NEW)
        {
            $image = slideshow_model::get_first_element();
            $this->view_data['image'] = $image;
            $this->view_data['style'] = show_style_model::$STYLE_SLIDE;
            $this->load_view('home');
        }
        else
        {
            $images = slideshow_model::get_elements();
            $this->view_data['images'] = $images;
            $this->view_data['style'] = show_style_model::$STYLE_NEW;
            $this->view_data['first_item'] = slideshow_model::get_first_element();
            $this->load_view('home_slide_show');
        }
    }

    public function get_more_image()
    {
        $result = array();
        $items = slideshow_model::get_elements();
        $result['style'] = show_style_model::get_element_by_code(show_style_model::$CODE)->style;
        $result['count'] = count($items);
        $result['items'] = $items;

        echo json_encode($result);
    }

    public function change_image()
    {
        $style = show_style_model::get_element_by_code(show_style_model::$CODE)->style;
        $id = $this->input->post('id');
        $image = slideshow_model::get_first_element();
        $result = array(
            'id' => $image->id,
            'path' => base_url() . $image->image_path,
            'new' => ($id == $image->id) ? false : true,
            'style' => $style
        );
        echo json_encode($result);
    }


}

?>